<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>push</title>
</head>
<body>
	<script>
        // push
        /*
        入栈，在数组的最后添加一个元素
        返回值：数组长度
        原数组新增插入的数
        */
        /*
        var arr = [1,2,3,4];
        var result = arr.push(5);
        console.log(arr);
        console.log(result);
        */
        
        // 重构
        // push单个数
        /*Array.prototype.myPush = function () {
            arr[this.length] = arguments[arguments.length-1];
            return this.length;
        }
        var arr = [1,2,3,4];
        var result = arr.myPush(5);
        console.log(arr);
        console.log(result);*/

        // push多个数
		Array.prototype.myPush = function () {
            for(var i = 0;i<arguments.length;i++){
                arr[this.length] = arguments[i];
                console.log(arr,'---');
            }
            return this.length;
        };
        var arr = [1,2,3,4];
        var result = arr.myPush("hello",5,"ddd");
        console.log(arr);
        console.log(result);

	</script>
</body>
</html>